/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.click.app.dao.hibernate;

import com.click.app.dao.DistinctiveNameDao;
import com.click.app.model.DistinctiveName;
import com.click.app.model.Material;
import java.util.ArrayList;
import java.util.List;
import org.springframework.orm.hibernate3.HibernateTemplate;

/**
 *
 * @author orgale
 */
public class DistinctiveNameDaoHibernate extends GenericDaoHibernate<DistinctiveName, Long> implements DistinctiveNameDao {

    public DistinctiveNameDaoHibernate() {
        super(DistinctiveName.class);
    }

    public List<DistinctiveName> findById(Long id) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
 

    public List<DistinctiveName> findDistinctiveNames() {
        List<DistinctiveName> dList = new ArrayList<DistinctiveName>();
        List<DistinctiveName> all = (List<DistinctiveName>) getHibernateTemplate().find("from DistinctiveName as d order by d.name");
        dList.add(all.get(0));
	String name = all.get(0).getName();
        for (int i = 1; i < all.size(); i++) {
		if(!all.get(i).getName().equals(name)){
			dList.add(all.get(i));
			name = all.get(i).getName();
		}
        }
        return dList;
    }

    public List<String> distinctiveNamesNames() {
        return getHibernateTemplate().find("select distinct name from DistinctiveName");
    }

    public List<DistinctiveName> findDistinctiveNamesName(String name) {
        return getHibernateTemplate().find("from DistinctiveName where name=?", name);
    }

    public List<DistinctiveName> findDistinctiveNamesByName(String name) {
        return getHibernateTemplate().find("from DistinctiveName where name=?", name);
    }

}
